from kmeans import *
from data import *

classes = generate_three_classes(radius=30)
visualize_classes(classes)
class1, class2, class3 = classes

train_matrix = np.concatenate(classes)
train_labels = np.concatenate((np.zeros(100), np.ones(100), np.ones(100) * 2))

clusters = 3
a = kmeans(clusters, 100, train_matrix, train_labels)
a.fit()

label_num = np.zeros((clusters, 3))

for i in range(a.classifications.shape[0]):
    pred = int(a.classifications[i])
    truth = int(train_labels[i])
    label_num[pred][truth] += 1


label2num = label_num.argmax(axis=1)
set(label2num)

train_preds = np.zeros(train_labels.shape)
for i in range(train_preds.shape[0]):
    train_preds[i] = label2num[a.classifications[i]]

print("随机生成300个数据聚类准确率", (np.sum(train_preds == train_labels) / train_labels.shape[0]))
